package tt.dz.dao.pro;

import java.util.List;

import org.springframework.stereotype.Repository;

import tt.dz.dao.base.BaseDao;
import tt.dz.entity.UserPayCard;

/**
 * 用户支付卡操作Dao类
 * @author xielf
 *
 * @param <T>
 */
@Repository
@SuppressWarnings(value={"unchecked","rawtypes"})
public class UserPayCardDao<T> extends BaseDao {

	/**
	 * 根据地区号查询最大流水
	 * @param areaNum
	 * @return
	 */
	public Integer getMaxSerialNumByAreaNum(Integer areaNum){
		
		List<String> list = super.findBySql("SELECT max(serial_num) FROM user_pay_card WHERE area_num=?", null, areaNum);
		String resultStr = list.get(0);
		if(resultStr==null){
			return 0;
		}
		Integer maxSerialNum = Integer.parseInt(resultStr);
		if(maxSerialNum!=null && maxSerialNum!=0){
			return maxSerialNum;
		}
		return 0;
	}
	/**
	 * 通过卡号查询卡详细信息
	 * @param userCardNum
	 * @return
	 */
	public UserPayCard findUserPayCardByCardNum(String userCardNum){
		List<UserPayCard> userPayCards = super.findByHql("from UserPayCard where user_card=?", userCardNum);
		if(userPayCards!=null && userPayCards.size()>0){
			return userPayCards.get(0);
		}
		return null;
	}
	/**
	 * 通过用户ID查询用户支付卡详细信息
	 * @param userCardNum
	 * @return
	 */
	public UserPayCard findUserPayCardByUserId(Integer userId){
		List<UserPayCard> userPayCards = super.findByHql("from UserPayCard where user_id=?", userId);
		if(userPayCards!=null && userPayCards.size()>0){
			return userPayCards.get(0);
		}
		return null;
	}
}
